


import pulp as plp

# 固定值 c1 到 c10（你可以根据需要修改）
c = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]  # 示例值，你可以替换为你自己的值

# 创建问题实例
prob = plp.LpProblem("MultiObjective_ILP", plp.LpMaximize)

# 定义变量
x = plp.LpVariable.dicts("x", range(1, 11), lowBound=0, upBound=1000, cat=plp.LpInteger)
y = plp.LpVariable.dicts("y", range(1, 11), cat=plp.LpBinary)

# 新增变量用于合并目标函数
big_weight = 100000  # 权重用于第一个目标 (maximize x3 + x4 + x5)
small_weight = 1     # 权重用于第二个目标 (minimize sum(c_i * y_i))

# 添加目标函数: maximize big_weight*(x3 + x4 + x5) - small_weight*sum(c[i]*y[i+1])
prob += big_weight * (x[3] + x[4] + x[5]) - small_weight * plp.lpSum([c[i] * y[i+1] for i in range(10)])

# 添加约束：x1 == x2 == x3 == x9
prob += x[1] == x[2]
prob += x[2] == x[3]
prob += x[3] == x[9]

# 添加约束：x2 + x7 == x8 + x9 == x4
prob += x[2] + x[7] == x[4]
prob += x[8] + x[9] == x[4]

# 添加约束：yi 表示 xi > 0，即 xi <= M * yi （M = 1000）
M = 1000
for i in range(1, 11):
    prob += x[i] <= M * y[i]
    # 当 xi == 0 时，yi 可以是 0；当 xi > 0 时，yi 必须是 1

# 求解问题
prob.solve(plp.PULP_CBC_CMD(timeLimit=30))  # 设置求解时间限制

# 输出结果
print("Status:", plp.LpStatus[prob.status])
print("Objective value =", plp.value(prob.objective))

# 打印变量取值
for i in range(1, 11):
    print(f"x{i} = {plp.value(x[i])}, y{i} = {plp.value(y[i])}")